package com.charmpeach.tsss;

import java.util.List;

import android.content.Context;
import android.opengl.Visibility;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class CommentArrayAdapter extends ArrayAdapter<String>{

	private final LayoutInflater mInflater;
	
	public CommentArrayAdapter(Context context) {
		super(context, 0);
		mInflater=LayoutInflater.from(getContext());
	}
	
	
	public View getView(int position, View convertView, ViewGroup parent)
	{
		View  rowView;
		//System.out.println(getItem(position));
		if(convertView==null)
		    rowView = mInflater.inflate(R.layout.forum_layout, parent, false);
		else {
			rowView=convertView;
		}
		String info[]=getItem(position).split("\\$");
		TextView titleView=(TextView)rowView.findViewById(R.id.forum_title);
		TextView autherView=(TextView)rowView.findViewById(R.id.forum_authorContent);
		TextView dateView=(TextView)rowView.findViewById(R.id.forum_date);
		TextView indexView=(TextView)rowView.findViewById(R.id.forum_index);
		TextView quotingAuthorView=(TextView)rowView.findViewById(R.id.forum_quotingAuthor);
		TextView quotingContentView=(TextView)rowView.findViewById(R.id.forum_quotingContent);
		TextView contentView=(TextView)rowView.findViewById(R.id.forum_content);
		autherView.setText(info[0]);
		dateView.setText(info[1]);
		if(info[2].equals(" "))
		{
			rowView.findViewById(R.id.forum_quoting).setVisibility(View.GONE);
			quotingAuthorView.setVisibility(View.GONE);
			quotingContentView.setVisibility(View.GONE);
		}
		else {
			quotingAuthorView.setText(info[2]);
			quotingContentView.setText(info[3]);
		}
		contentView.setText(Html.fromHtml(info[4]));
		indexView.setText(String.valueOf(position));
		if (position>=1) {
			titleView.setText("Re:"+info[5]);
		}
		else {
			titleView.setText(info[5]);
		}
		return rowView;
	}

}
